package com.dounine.clouddisk360.parser.deserializer.user.size;

import java.io.IOException;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSON;
import com.dounine.clouddisk360.parser.UserSizeParser;
import com.dounine.clouddisk360.parser.UserTokenParser;

public class UserSizeResponseHandle implements ResponseHandler<UserSize> {
	
	private UserSizeParser userSizeParser;
	public UserSizeResponseHandle(UserSizeParser userSizeParser) {
		this.userSizeParser = userSizeParser;
	}

	@Override
	public UserSize handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
		HttpEntity entity = response.getEntity();
		String result = EntityUtils.toString(entity, Consts.UTF_8);
		return desializer(result);
	}
	
	public String disassemblyResult(String result) {
		String _result = null;
		_result = result.substring(result.indexOf("{"), result.lastIndexOf("}") + 1);
		return _result;
	}

	public UserSize desializer(String result) {
		if (StringUtils.isNotBlank(result)) {
			result = disassemblyResult(result);
			return JSON.parseObject(result, UserSize.class);
		}
		return null;
	}

}
